<?php
/* 
* @Author: LDF QQ 47121862
* @Date:   2014-06-07 10:33:42
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-06-11 14:27:49
*/
Class XilieControl extends AuthControl{
	public $model;
	public $xid;
	function __auto(){
		$this->model=K('Xilie');
		$this->xid=Q('xid',0,'intval');
	}
	//首页列表
	function index(){
		$page=new Page($this->model->count());
		$this->xilie=$this->model->limit($page->limit())->order('xid DESC')->all();
		$this->page=$page->show();
		$this->display();
	}
	//添加系列
	function add(){
		if(IS_POST){
			if($this->model->addXilie()){
				$this->success('添加系列成功');
			}else{
				$this->error($this->model->error);
			}
		}else{
			$this->display();
		}
	}
	//修改系列
	function edit(){
		if(IS_POST){
			if($this->model->editXilie()){
				$this->success('修改系列成功');
			}else{
				$this->error('修改失败');
			}
		}else{
			$xid=Q('xid',0,'intval');
			$this->field=M('xilie')->find($xid);
			$this->display();
		}
	}
	//删除系列
	function del(){
		if($this->model->delXilie()){
			$this->success('删除系列成功');
		}else{
			$this->error('删除失败');
		}
	}
	//===========剧集============
	//剧集列表
	function juji(){
		$page=new Page(M('juji')->where('xid='.$this->xid)->count());
		$this->page=$page->show();
		$this->juji=M('juji')->where('xid='.$this->xid)->limit($page->limit())->order('jid DESC')->all();
		$this->display();
	}
	//添加剧集
	function addJuji(){
		if(IS_POST){
			if(empty($_POST['url'])) $this->error('链接地址不能为空');
			if(M('juji')->add($_POST)){
				//更改当前系列显示的集数
				$count=M('juji')->where(array('xid'=>$this->xid))->count();
				$this->model->save(array('xid'=>$this->xid,'act'=>$count));
				$this->success('剧集添加成功');
			}else{
				$this->error('剧集添加失败');
			}
		}else{
			$this->display();
		}
	}
	//修改剧集
	function editJuji(){
		if(IS_POST){
			M('juji')->save($_POST)?$this->success('修改剧集成功...'):$this->error('修改剧集失败...');
		}else{
			$jid=Q('jid',0,'intval');
			$juji=M('juji')->find($jid);
			$this->field=$juji;
			$this->display();
		}
	}
	//删除剧集
	function delJuji(){
		$jid=Q('jid',0,'intval');
		if(M('juji')->del($jid)){
			//更改当前系列显示的集数
			$this->model->dec('act','xid='.$this->xid,1);
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
	}
}